﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;

namespace Grundy.Message
{
    
    [CollectionDataContract]
    public class ProductsCollection : ICollection<Product>
    {
        private List<Product> _products;

        public ProductsCollection()
        {
            _products = new List<Product>();
        }

        public ProductsCollection(IEnumerable<Product> products)
        {
            _products = products.ToList();
        }

        public IEnumerator<Product> GetEnumerator()
        {
            return _products.GetEnumerator();
        }

        IEnumerator IEnumerable.GetEnumerator()
        {
            return GetEnumerator();
        }

        public void Add(Product item)
        {
            _products.Add(item);
        }

        public void Clear()
        {
            _products.Clear();
        }

        public bool Contains(Product item)
        {
            return _products.Contains(item);
        }

        public void CopyTo(Product[] array, int arrayIndex)
        {
            _products.CopyTo(array, arrayIndex);
        }

        public bool Remove(Product item)
        {
            return _products.Remove(item);
        }

        public int Count
        {
            get { return _products.Count; }
        }

        public bool IsReadOnly
        {
            get { return false; }
        }
    }
}